<template>
  <div style="width: 1000px;margin: 20px auto">
    <el-form :model="editPwdForm" ref="editPwdForm" label-width="80px" style="width: 500px">
      <el-form-item label="新密码" prop="password">
        <el-input v-model="editPwdForm.password" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="margin-right: 1000px">
      <el-button type="info" @click="submitEditPwdForm">修 改</el-button>
    </div>
  </div>
</template>
<script>
import global from '../../Global'
let preAdminUrl = global.preAdmins ;
let preResourceUrl = global.preResources ;
export default {
  data() {
    return {
      dialogPwdFormVisible: false,
      editPwdForm: {
        password: ''
      }
    }
  },
  methods: {
    //密码修改提交
    submitEditPwdForm(){
      let url = preAdminUrl + "/" + this.editPwdForm.id + "/updatePwd";
      let formData = this.qs.stringify(this.editPwdForm);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .post(url, formData).then((response) => {
        let jsonResult = response.data;
        if(jsonResult.state == 20000){
          this.$notify.success({title: '成功',
            message: '修改密码成功！'
          });

          this.dialogPwdFormVisible = false;
        }else if(jsonResult.state == 40400 || jsonResult.state == 40100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
              localStorage.removeItem("localJwt");
              this.$router.push("/login");
            }
          });
        }else{
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    },
    //获取当事人信息
    loadLoginPrincipal(){
      let url = preAdminUrl + "/index";

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if(jsonResult.state == 20000){
          this.editPwdForm = jsonResult.data;
        }else if(jsonResult.state == 40400 || jsonResult.state == 40100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
              this.dialogFormVisible = false;
              localStorage.removeItem("localJwt");
              this.$router.push("/webLogin");
            }
          });
        }else{
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    }
  },
  mounted() {
    this.loadLoginPrincipal();
  }
}
</script>